package com.yugao.fintech.antelope.base.model.module.tenant;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;


@Slf4j
public class TenantContextHolder {
    private static final TransmittableThreadLocal<TenantContext> TTL = new TransmittableThreadLocal<>();

    public static void set(TenantContext content) {
        TTL.set(content);
    }

    public static TenantContext get() {
        TenantContext tenantContext = TTL.get();
        if (Objects.isNull(tenantContext)) {
            tenantContext = new TenantContext();
            TTL.set(tenantContext);
        }
        return tenantContext;
    }

    public static void clear() {
        TTL.remove();
    }
}
